//==========================================================  
// Class for Fps counter
//==========================================================

//// Variables
var numFrames = 0;
var lastSecond = 0;
var fpsText = '';
var currentTime = '';

//==========================================================  
// Enables FPS counter - Counter fps and displays it to fps Span element
//==========================================================
var enableFpsCounter = function ()
{
    currentTime = TurbulenzEngine.time;
    
    //// If we use canvas engine
    if (TurbulenzEngine.canvas)
    {
        numFrames += 1;

        if ((currentTime - lastSecond) >= 1)
        {
            fpsText = (numFrames / ((currentTime - lastSecond))).toFixed(2) +" fps";
            numFrames = 0;
            lastSecond = currentTime;
        }
    }
    else //// If we use graphicsDevice (sprite and other rendering)
    {
        fpsText =  (graphicsDevice.fps).toFixed(2) + " fps";
    }
    
    setFpsForDisplay();
}

function setFpsForDisplay() {
    
    if(fpsText == undefined)
    {
        fpsElement.innerHTML = lastFps;
    }
    else
    {
        lastFps = fpsText;
        fpsElement.innerHTML = fpsText;
    }
}